const mysql = require('mysql');
const pool = mysql.createPool({
	host:"localhost",
	user: "root",
	password:"root",
	database:"music_app",
	port:3306,
});
function query(sql, params){
	return new Promise((resolve, reject) => {
		pool.query(sql, params, (err, result) => {
			if(err){
				reject(err);
			}
			resolve(result);
		})
	})
}
// 测试数据库连接
async function testDBConnection() {
  try {
    const result = await query('SELECT 1 + 1 AS solution');
    console.log('数据库连接成功，测试结果:', result);
  } catch (err) {
    console.error('数据库连接失败:', err);
  }
}

// 执行测试
testDBConnection();
module.exports = {
	query
}